package nl.hanze.designpatterns.mvc.view;

import javax.swing.JFrame;

import nl.hanze.designpatterns.mvc.controller.MainAppGuiController;
import nl.hanze.designpatterns.mvc.model.MainModel;

public class MainAppGui extends Gui {
	
	private MenuBar menu;
	private MainAppGuiController mainAppGuiController;
	private View view;
	private MainModel model;
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MainAppGui(MainModel model){
		this.init(model);
		this.setVisible(true);
		this.addItems();
	}

	private void init(MainModel model){
		this.model = model;
		this.mainAppGuiController = new MainAppGuiController(this, this.model);
		this.setView(new ShowTicketsView(this.model));
		this.setTitle("Design Patterns");
		this.setSize(800, 600);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.menu = new MenuBar(this.mainAppGuiController);
		this.setJMenuBar(menu);
	}
	
	private void addItems(){
		this.add(this.view);
	}
	
	public void changeViews(View view){
		this.remove(this.view);
		this.setView(view);
		this.add(this.view);
		this.validate();
	}
	
	//getter and setters
	public void setView(View view){
		this.view = view;
	}
	
	public View getView(){
		return this.view;		
	}
}
